package com.meal.entity.config;

import org.springframework.stereotype.Component;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class WebContextListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        //在ServletContext中增加静态资源版本号
        String staticVersion = new SimpleDateFormat("yyyyMMddhhmmssSSS").format(new Date());
        ServletContext servletContext = servletContextEvent.getServletContext();
        servletContext.setAttribute("staticVersion", staticVersion);
        /*
        * 初始化数据
        * @TODO
        * */
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        ServletContext servletContext = servletContextEvent.getServletContext();
        servletContext.removeAttribute("staticVersion");
        /*
         * 备份数据
         * @TODO
         * */
    }
}
